package com.gy.boot.controller;

import cn.hutool.extra.servlet.ServletUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@RestController
@RequestMapping("/auth")
public class AuthController {

    /**
     * 微信测试公众号Token认证
     */
    @ResponseBody
    @GetMapping("/wx")
    public void wxAuth(HttpServletRequest request, HttpServletResponse response) throws IOException {
        Map<String, String> paramMap = ServletUtil.getParamMap(request);
        String echoStr = paramMap.get("echostr");
        System.out.println(echoStr);
        PrintWriter out = response.getWriter();
        out.write(echoStr);
        System.out.println("微信服务验证成功！");
        out.flush();
        out.close();
    }

}